<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="app">
        <p>msg:{{msg}}</p>
        <input type="text" v-model="msg">
        <hr>
        <p>info:{{info}}</p>
        <hr>
        <comp-a :msg="msg"></comp-a>
    </div>
    <div id="root">
        <p>msg:{{msg}}</p>
        <input type="text" v-model="msg">
    </div>
    <template id="child">
        <div>
            <p>msg:{{msg}}</p>
            <input type="text" v-model="msg">
            <hr>
            <p>aaa:{{aaa}}</p>
        </div>
    </template>
</body>
<script>
    const state = Vue.observable({
        msg:"初始变量",
        user:{
            name:"周星驰",
            age:50
        }
    });
    console.log(state);
    new Vue({
        el:"#app",
        components:{
            compA:{
                template:"#child",
                // data(){
                //     return state;
                // }
                data(){
                    return{
                        aaa:"小团团"
                    }
                },
                computed:{
                    msg:{
                        get(){
                            return state.msg;
                        },
                        set(nv){
                            state.msg=nv;
                        }
                    }
                }
            }
        },
        // data:state
        data:{
            info:"info变量"
        },
        computed:{
            msg:{
                get(){
                    return state.msg;
                },
                set(nv){
                    state.msg=nv;
                }
            }
        }
    });
    new Vue({
        el:"#root",
        data:state
    })
</script>
</html>